/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	XMLParser.cpp
*
*	Comments	-	See XMLParser.h
*
**************************************************************************************/
#include "../Include/XMLParser.h"
#include "../Include/String.h"
#include "../Include/FileSystem.h"
#include "../Include/Engine.h"
#include "../Include/ResourceCache.h"
#include "../External/tinyxml2/tinyxml2.h"


namespace Pulse
{
	void Recursive( XMLElementPtr pElem )
	{
		if ( pElem->IsValid() == FALSE )
			return;
		
		String val;
		
		val = pElem->GetName();
		val = pElem->GetValue();

		XMLElementPtr pChild = pElem->GetFirstChild();

		while ( pChild->IsValid() )
		{
			Recursive( pChild );
			pChild = pChild->GetNextSibling();
		}

	};

	PSX_REGISTRY_OBJECT_START( XMLParser, ERegistryPriority::Normal, ERegistryPriority::Normal )
		PSX_REGISTRY_ON_TEST()
		{
			/*XMLDocumentPtr pDoc = XMLParser::Load( PSX_String("Resources\\XML\\Personal.xml") );

			if ( pDoc.IsNull() == FALSE )
			{
				Recursive( pDoc->GetFirstChild() );
			}*/

			return EErrorCode::OKAY;
		}
	PSX_REGISTRY_OBJECT_END();

	BOOL XMLParser::m_bValidation = TRUE;

	XMLParser::~XMLParser( void )
	{

	}

	EErrorCode::Type XMLParser::Initialize( void )
	{

		return EErrorCode::NONE;
	}

	void XMLParser::Shutdown( void )
	{

	}

	XMLDocumentPtr XMLParser::Load( const CHAR *pFilename )
	{
		XMLDocumentPtr pDoc(new XMLDocument(pFilename));

		if ( pDoc->IsValid() )
			return pDoc;
		else 
			return PSX_NULL;
	}

	void XMLParser::SetValidate( BOOL validate )
	{
		m_bValidation = validate;
	}
}